<?php
/**
 * Created by PhpStorm.
 * User: yys
 * Date: 2016/11/28
 * Time: 17:02
 */

namespace App\Services\ProdTempCategoryService;


use Illuminate\Support\Facades\DB;

class ProdTempCategoryTool
{
    /****
     * 判断产品模板分类是不是存在
     * @param $temp_category_id
     * @return bool
     */
    public static function productTempCategoryExistsByProdTempCategoryId($temp_category_id)
    {
        if(empty($temp_category_id)){
            return false;
        }
        $num= DB::table('product_temp_categorys')->where(array('state'=>1,'id'=>$temp_category_id))
            ->count();
        return ($num===0)?false:true;
    }
    /***
     * 获取产品分类名
     * @param $temp_category_id
     * @return string
     */
    public static function productTempCategoryNameByProdTempCategoryId($temp_category_id)
    {
        if(empty($temp_category_id)){
            return '';
        }
        $name= DB::table('product_temp_categorys')->where(array('state'=>1,'id'=>$temp_category_id))
            ->value('name');
        return empty($name)?'':$name;
    }
    /***
     * 获取产品模板分类
     * @return array
     */
    public static function getProdTempCategoryList()
    {
        $product_temp_categorys= DB::table('product_temp_categorys')->where('state',1)
            ->select('name','id')
            ->get()
            ->toArray();
        return empty($product_temp_categorys)?array():$product_temp_categorys;
    }
}